package com.example.microservice.http.impl.server;

import java.util.ArrayList;
import java.util.List;

import com.example.microservice.bo.server.map.MapCenterPointBo;
import com.example.microservice.common.utils.MapCenterPointUtil;
import com.example.microservice.dto.server.map.MapCenterPoint;
import com.example.microservice.http.service.server.MapGround2CenterPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @Author: caohuijie
 * @Date: 创建日期 2018/11/7
 * @Modified By:
 * @Description:
 */
@Service
public class MapGround2CenterPointServiceImpl implements MapGround2CenterPoint {


    @Autowired
    private  MapCenterPointUtil mapCenterPointUtil;

    @Override
    public List<MapCenterPoint> mapCenterPoint(List<MapCenterPointBo> points) {
        List<MapCenterPoint> updatePoint = new ArrayList<>();
        //拼装数据
        points.forEach(point -> {
            //如果为空值，则不去转换，
            if (point != null && !point.getPoints().isEmpty()) {
                String centerPoint = mapCenterPointUtil.getCenterPoint(point.getPoints());
                if (centerPoint.contains(",") && centerPoint.split(",").length >= 2) {
                    String coordx = centerPoint.split(",")[0];
                    String coordy = centerPoint.split(",")[1];
                    MapCenterPoint mapCenterPointModel = new MapCenterPoint();
                    mapCenterPointModel.setUniqueId(point.getUniqueId());
                    mapCenterPointModel.setCoordx(coordx);
                    mapCenterPointModel.setCoordy(coordy);
                    updatePoint.add(mapCenterPointModel);
                }
            }
        });
        return updatePoint;
    }
}
